package top.jiangqiang.qianyi.common.base.model.request;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import top.jiangqiang.qianyi.common.base.model.response.PageResult;

import java.io.Serial;
import java.io.Serializable;

/**
 * @Date 2024/1/12 9:46
 * @Author Jiangqiang
 */
@Data
public class BasePageRequest implements Serializable {
    @Serial
    private static final long serialVersionUID = 1L;
    @Schema(description = "查询第几页的数据，默认第一页", defaultValue = "1")
    protected Long current;
    @Schema(description = "每一页的数量，默认10条，传入-1则不分页", defaultValue = "10")
    protected Integer size;

    public <T> PageResult<T> toPage() {
        long index = 1;
        int size = 10;
        if (this.current != null) {
            index = this.current;
        }
        if (this.size != null) {
            size = this.size;
        }
        return new PageResult<>(index, size);
    }
}
